//
//  NavisearchCell.m
//  quickLook
//
//  Created by J on 15/8/31.
//  Copyright (c) 2015年 JZJ. All rights reserved.
//

#import "NavisearchCell.h"
#import "LandController.h"

#import "RightCollectionClickController.h"
#import "FindViewSeeMoreController.h"
#import "Model.h"

#import "Header.h"
@interface NavisearchCell ()
{
    
    NSIndexPath* _indexPath;
}


@property(nonatomic,strong)Model* model;

@property (weak, nonatomic) IBOutlet UIImageView *cover_image_url;

@property (weak, nonatomic) IBOutlet UILabel *title;

@property (weak, nonatomic) IBOutlet UILabel *nickname;


//点赞个数
@property (weak, nonatomic) IBOutlet UILabel *likes_count;

//评论个数
@property (weak, nonatomic) IBOutlet UILabel *comments_count;



@property (weak, nonatomic) IBOutlet UILabel *created_at;
@property (weak, nonatomic) IBOutlet UIButton *attention;
@property (weak, nonatomic) IBOutlet UIImageView *goodTapView;

@end
@implementation NavisearchCell

- (void)awakeFromNib {
    // Initialization code
    _attention.layer.cornerRadius=10;
    
    UITapGestureRecognizer* goodTap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(goodTap:)];
    
    _attention.userInteractionEnabled=YES;
    _goodTapView.userInteractionEnabled=YES;
    [_goodTapView addGestureRecognizer:goodTap];
    
    
    

    
}

- (void)goodTap:(UITapGestureRecognizer*)tap{
    
//    JZJLog(@"dddddddddddddddddddddddddddxxx");
    
    [UIView animateWithDuration:0.3 animations:^{
        
        _goodTapView.transform= CGAffineTransformScale(CGAffineTransformIdentity, 2.0, 2.0);
        
        if ((tap.view.tag=!tap.view.tag)) {
            
            _likes_count.textColor=[UIColor colorWithRed:135/255.0 green:135/255.0  blue:135/255.0  alpha:1.0];
            
            
            
            
            _goodTapView.image=[UIImage imageNamed:@"quickLook2Hilighted.png"];
            _likes_count.textColor=JZJYELLOW;
            
        }else{
            
            _likes_count.textColor=TEXTCOLOR;
            
            _goodTapView.image=[UIImage imageNamed:@"quickLook2.png"];
            
            
            
            
        }
        
        
        
        
        Model* model= self.delegate.dataArray[_indexPath.row];
        
        
        
        [DownLoad  getWetherDataWithID:model.id andBlock:^(NSDictionary* obj, NSError *error) {
            
            {
                
                NSString* str=obj[@"message"];
                
                
                if ([str isEqual:@"OK"]) {
                    
                    
                    [self.delegate.tableView reloadRowsAtIndexPaths:@[_indexPath] withRowAnimation:UITableViewRowAnimationFade];
                    
                    //                    _thumber.image=[UIImage imageNamed:@"quickLook2Hilighted.png"];
                }
                
                
                
                
                //                _thumber.image=[UIImage imageNamed:@"quickLook2"];
                
                
            }
        }];
        
        
        
        
        
        
        
        
    } completion:^(BOOL finished) {
        
        
        [UIView animateWithDuration:0.3 animations:^{
            _goodTapView.transform= CGAffineTransformScale(CGAffineTransformIdentity, 1.0, 1.0);
            
        }];
        
        
    }];
    
    
    
    
    
}

- (IBAction)isLiked:(id)sender {
    
    
    
    
    
    
}



- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}


- (void)ThirdNaviSearchControllerrefreshWithModel:(Model*)model WithIndexPath:(NSIndexPath*)path
{

    
//    JZJLog(@"ThirdNavisearchCell");
    
    
    
    [_cover_image_url sd_setImageWithURL:[NSURL URLWithString:model.cover_image_url]];
    
    
    _title.text=model.title;
    
    
    
    NSString *str=[NSString stringWithFormat:@"%@",model.created_at];//时间戳
    NSTimeInterval time=[str doubleValue]+28800;//因为时差问题要加8小时 == 28800 sec
    NSDate *detaildate=[NSDate dateWithTimeIntervalSince1970:time];
//    JZJLog(@"date:%@",[detaildate description]);
    //实例化一个NSDateFormatter对象
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    //设定时间格式,这里可以设置成自己需要的格式
    [dateFormatter setDateFormat:@"MM-dd"];
    NSString *currentDateStr = [dateFormatter stringFromDate: detaildate];

    
    
    
    
    
    
    _created_at.text=currentDateStr;
    
    _likes_count.text=[NSString stringWithFormat:@"%@",model.likes_count];



    
    
    
    
}


- (void)refreshWithModel:(Model*)model WithIndexPath:(NSIndexPath*)path
{
    
    
    
    _indexPath=path;
    _goodTapView.tag=path.row;
    
    _model=model;
    
//    JZJLog(@"cell刷新");
    
    _title.text=model.title;
    
    _nickname.text=model.user[@"nickname"];
    
    _comments_count.text=[NSString stringWithFormat:@"%d万",[model.comments_count intValue]/10000 ];
    _likes_count.text =[NSString stringWithFormat:@"%d万",[model.likes_count intValue]/10000];
  
    [_cover_image_url sd_setImageWithURL:[NSURL URLWithString:model.cover_image_url]];

}
- (IBAction)thumb:(id)sender {
    
    
    NSUserDefaults* userdefatult=[NSUserDefaults standardUserDefaults];
    
    //如果没有的登录 跳转到登录页面
    
    if (![userdefatult boolForKey:ISLAND]) {
        
        LandController * vc=[[LandController alloc]init];
        

        [self.findVCDelegate presentViewController:vc animated:YES completion:nil];
        
        
        
    }else//发送请求
    {
    
    
    
    }
    
}




@end
